package behaviors;

import math.Maths;
import math.vector.Vecmath;
import math.vector.vec2f;
import math.vector.vec3f;

public class Rotation
{
    
    private vec2f rots; // rotations, stored as (pitch, yaw)
    //<editor-fold defaultstate="collapsed" desc="getRots">
    public vec2f getRots()
    {
        return this.rots;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="setRots">
    public void setRots(float xRot, float yRot)
    {
        this.rots.setTo(xRot, yRot);
    }
    
    public void setRots(vec2f newRots)
    {
        this.setRots(newRots.x, newRots.y);
    }
    //</editor-fold>
    
    private vec2f rotsStart;
    //<editor-fold defaultstate="collapsed" desc="getRotsStart">
    public vec2f getRotsStart()
    {
        return this.rotsStart;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="setStart">
    public void setStart(float xRot, float yRot)
    {
        this.rotsStart.setTo(xRot, yRot);
        this.setRots(xRot, yRot);
    }
    
    public void setStart(vec2f startRots)
    {
        this.setStart(startRots.x, startRots.y);
    }
    //</editor-fold>
    
    public Rotation()
    {
        this.rots = new vec2f();
        this.rotsStart = new vec2f();
    }
    
    public void updateRots(float dXRot, float dYRot)
    {
        this.rots.x += dXRot;
        this.rots.y += dYRot;
        this.rots.x = Maths.mod(this.rots.x, Maths.PI_TIMES_2);
        this.rots.y = Maths.mod(this.rots.y, Maths.PI_TIMES_2);
    }
    
    public void resetRotsToStart()
    {
        this.rots.setTo(this.rotsStart);
    }
    
    public vec3f getDir()
    {
        vec3f dir = Vecmath.getDirectionFromSpherical(this.rots.x, this.rots.y);
        return dir;
    }
    
    public String toString()
    {
        String s = "";
        s += "ROTATION BEHAVIOR: ";
        s += "\n   rots: " + this.rots;
        s += "\n   dir: " + this.getDir();
        return s;
    }
    
    public void destroy()
    {
        this.rots = null;
        this.rotsStart = null;
    }
    
}
